package com.github.m6d21.sso.common.util;

import javax.servlet.http.Cookie;

public class CookieBuilder {


    private final Cookie cookie;

    private CookieBuilder(String key, String value) {
        this.cookie = new Cookie(key, value);
    }

    public static CookieBuilder cookie(String key, String value) {
        return new CookieBuilder(key, value);
    }

    public CookieBuilder path(String path) {
        this.cookie.setPath(path);
        return this;
    }

    public CookieBuilder maxAge(int expire) {
        this.cookie.setMaxAge(expire);
        return this;
    }

    public CookieBuilder domain(String domain) {
        this.cookie.setDomain(domain);
        return this;
    }

    public CookieBuilder comment(String comment) {
        this.cookie.setComment(comment);
        return this;
    }

    public CookieBuilder secure(boolean secure) {
        this.cookie.setSecure(secure);
        return this;
    }

    public CookieBuilder httpOnly(boolean httpOnly) {
        this.cookie.setHttpOnly(httpOnly);
        return this;
    }

    public Cookie build() {
        return this.cookie;
    }

}
